// pages/nakedEyeDetails/nakeEyeDetails.js
var request = require("../../utils/request.js")
const app = getApp();
var wxCharts = require("../../js/wxcharts.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabTitle: ["记录", "趋势"],
    width: 20,
    num: 0,
    current: "记录",
    testInfo: [],
    result: "",
    options: {}
  },
  TabClick: function (e) {
    console.log(e)
    this.setData({
      num: e.detail.num,
      current: this.data.tabTitle[e.detail.num]
    })
  },
  //图表趋势
  runLineCanva: function (d1, d2, t) {
    console.log(d1);
    new wxCharts({
      canvasId: "lineCanvas",
      type: "line",
      categories: t,
      background: "#fff",
      series: [
        {
          name: "左眼",
          data: d1,
          color: "#ffa621",

        },
        {
          name: "右眼",
          data: d2,
          color: "#3be961",

        },
      ],
      yAxis: {
        name: "度",
      },
      xAxis: {
        // title:'日期',
        name: "日期"
      },
      width: "350",
      height: 220,
      legend: false,
      //dataLabel: false,
      dataPointShape: 'circle',
      extra: {
        lineStyle: 'curve'
      }
    });
  },
  //屈光视力详情
  showEyeDetails: function (a) {
    var that = this;
    that.toastDialog.showDialog({ code: 'loading', message: '加载中', timeout: false }); //loading 加载框
    that.setData({ loading: true })

    let url = "xcx/testInfo";
    let data = {
      type: 2,
      tid: a
    }
    request.postData(url, data, function (res) {
      console.log(res);
      that.toastDialog.hideDialog(); //关闭loading提示框
      that.setData({ loading: false })
      if (res.code == 0) {
        that.setData({
          testInfo: res.testInfo,
          result: res.tips
        })
      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }

    }, function (res) {
      that.setData({ loading: false })
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });

  },
  //切换他人
  gotoChangePersion: function (e) {
    console.log(e);
    wx.navigateTo({
      url: '../changePersionList/changePersionList?type=2'
    })
  },
  //趋势图表
  showChartsDetails: function () {
    let that = this
    that.toastDialog.showDialog({ code: 'loading', message: '正在提交', timeout: false }); //loading 加载框

    request.postData('xcx/trendData', { type: 2, uid: that.data.options.uid }, function (res) {
      that.toastDialog.hideDialog(); //关闭loading提示框

      that.setData({ loading: false })
      if (res.code == 0) {
        that.runLineCanva(res.data1, res.data2, res.title);
      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }

    }, function (res) {
      that.setData({ loading: false })
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toastDialog = this.selectComponent("#toastDialog");//此处id和页面的 wxml中的id一致

    this.showEyeDetails(this.options.tid);
    this.showChartsDetails();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.options);
    // if(wx.getStorageSync("uid")!=undefined && wx.getStorageSync("uid")!=''){
    //   options.uid=wx.getStorageSync("uid")
    // }
    this.setData({ options: options })
    wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
  },
/**
 * 用户点击右上角分享
 */
onShareAppMessage (res) {
  return {
    title: '迪佳极视',
    path: 'pages/index/index',
    // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
    success: function (shareTickets) {
      console.info(shareTickets + '成功');
      // 转发成功
    },
    fail: function (res) {
      console.log(res + '失败');
      // 转发失败
    },
    complete:function(res){
      // 不管成功失败都会执行
    }
  }
},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})